package ${pkg};

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;

import javax.validation.ValidationException;

import org.junit.Assert;
import org.junit.FixMethodOrder;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.MethodSorters;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.transaction.annotation.Transactional;
import ${facadePkg}.${clazz}Facade;
import ${exceptionPkg}.${clazz}Exception;
import ${messagePkg}.${clazz}Request;
import ${messagePkg}.${clazz}Response;
<#if impList??>
<#list impList as vo>
import ${vo};
</#list>
</#if>

/**
 * ${name}Provider测试
 * 
 * @author 代码由 blue-code 框架生成
 * @since 1.0 ${.now?string("yyyy年MM月dd日")}
 */
@RunWith(SpringJUnit4ClassRunner.class)
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
@ContextConfiguration(locations={"classpath:spring/dao.xml", "classpath:spring/redis.xml", "classpath:spring/spring.xml"})
@Transactional
public class ${clazz}ProviderTest
{
	@Autowired
	private ${clazz}Facade ${field}Facade;
	
	public ${clazz}ProviderTest()
	{
	}
	
	private ${clazz}Request getRequest()
	{
		${clazz}Request request = new ${clazz}Request();
		<#if columnList??>
		<#list columnList as vo>
		<#if !vo.nullable>
		request.${vo.setter}("");
		</#if>
		</#list>
		</#if>
		return request;
	}
	
	// 测试添加
	@Test
	public void testAdd() throws Exception
	{
		${clazz}Request request = this.getRequest();
		
		${clazz}Response resp = ${field}Facade.add(request);
		Assert.assertNotNull("添加失败", resp);
		
		${clazz}Response response = ${field}Facade.get(resp.getId());
		Assert.assertNotNull("添加失败", response);
		<#if columnList??>
		<#list columnList as vo>
		<#if !vo.nullable>
		Assert.assertEquals("错误", request.${vo.getter}(), response.${vo.getter}());
		</#if>
		</#list>
		</#if>
	}
	
	// 测试更新
	@Test
	public void testUpdate() throws Exception
	{
		${clazz}Request request = this.getRequest();
		${clazz}Response resp = ${field}Facade.add(request);
		Assert.assertNotNull("添加失败", resp);
		<#if columnList??>
		<#list columnList as vo>
		<#if !vo.nullable>
		request.${vo.setter}("");
		</#if>
		</#list>
		</#if>
		request.setId(resp.getId());
		resp = ${field}Facade.update(request);
		Assert.assertNotNull("更新失败", resp);
		
		${clazz}Response response = ${field}Facade.get(resp.getId());
		Assert.assertNotNull("更新失败", response);
		<#if columnList??>
		<#list columnList as vo>
		<#if !vo.nullable>
		Assert.assertEquals("错误", request.${vo.getter}(), response.${vo.getter}());
		</#if>
		</#list>
		</#if>
	}
	
}
